package IC.lir;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import IC.Constants;
import IC.lir.instructions.Label;

/**
 * 
 * LIRClass Object
 *
 */
public class LIRDv extends LIRObject{

	private LIRClass ClassRef;
	private Map<Integer, LIRMethod> Methods;
	
	//C'tor
	public LIRDv() 
	{
		super();
		this.Methods = new LinkedHashMap<Integer, LIRMethod>();
	}
	
	//C'tor
	public LIRDv(Map<Integer, LIRMethod> Methods) 
	{
		super();
		this.Methods = new LinkedHashMap<Integer, LIRMethod>(Methods);
	}
	
	public void setClassRef(LIRClass ClassRef) {
		this.ClassRef = ClassRef;
		this.Label = new Label("_DV_" + this.ClassRef.getName());
	}
	
	public Map<Integer, LIRMethod> getMethods() {
		return Methods;
	}
	
	@Override
	public String toString() {
		StringBuffer s = new StringBuffer();
		if (!Methods.isEmpty()){
			boolean first = true;
			for (Entry<Integer, LIRMethod> m : Methods.entrySet()) {
				if (first) {
					s.append(Label + ": [" + m.getValue().getLabel());
					first = false;
				} 
				else 
					s.append("," + m.getValue().getLabel());	
			}
			s.append("]" + Constants.LINE_BREAK);
		} 
		else 
			s.append(Label + ": []" + Constants.LINE_BREAK);
		return s.toString();
	}	
}
